#include "StdAfx.h"
#include "LexicalAnalyzer.h"

CLexicalAnalyzer::CLexicalAnalyzer(void)
{
}

vector <string> CLexicalAnalyzer::GetTokens()
{
	char ch;
	string str;
	vector <string> tokens;

	while ( (ch = getchar()) != '\n' )
	{
		switch ( ch )
		{
			case ' ':
				if ( str != "" )
				{
					tokens.push_back(str);
					str = "";
				}
				break;
				
			case ';':
			case '(':
			case ')':
				if ( str != "" )
				{
					tokens.push_back(str);
					str = "";
				}
				tokens.push_back(str + ch);
				break;

			default:
				if ( isalpha( ch ) )
				{
					str += ch;
				}
				else
				{	
					if ( str == "//" )
					{
						return tokens;
					}
					
					cout << "Error! Enexpected character: " << ch << endl;
					vector < string > nul;
					return nul; 
				}
		}
	}

	if ( str != "" )
	{
		tokens.push_back(str);
	}

	return tokens;
}

CLexicalAnalyzer::~CLexicalAnalyzer(void)
{
}
